package com.zdlog.wenjuan.service.impl;

import com.sun.javafx.css.StyleCache;
import com.zdlog.wenjuan.VO.ResultBoolenVO;
import com.zdlog.wenjuan.dao.ResultInfoRepository;
import com.zdlog.wenjuan.dao.SubmitInfoRepository;
import com.zdlog.wenjuan.dataobject.ResultInfo;
import com.zdlog.wenjuan.dataobject.SubmitInfo;
import com.zdlog.wenjuan.service.SubmitService;
import com.zdlog.wenjuan.util.KeyUtil;
import com.zdlog.wenjuan.util.ResultBoolenVOUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: wenjuanSer
 * @PACKAGE_NAME: com.zdlog.wenjuan.service.impl
 * @author: Kuaile
 * @create: 2018-02-22 14:52
 **/
@Service
public class SubmitServiceImpl implements SubmitService{

    @Autowired
    private SubmitInfoRepository repository;


    @Autowired
    private ResultInfoRepository resultInfoRepository;


    @Override
    public ResultBoolenVO submitForm(SubmitInfo submitInfo, List<ResultInfo> resultInfoList) {
        try {
            SubmitInfo result = repository.save(submitInfo);
            for (ResultInfo resultInfo : resultInfoList) {
                resultInfo.setResultId(KeyUtil.genUniqueKey());
                resultInfoRepository.save(resultInfo);
            }
            if (result != null) {
                return ResultBoolenVOUtil.success();
            }
            return ResultBoolenVOUtil.success();
        } catch (Exception e) {
            return ResultBoolenVOUtil.error("提交失败");
        }
    }

}
